let rec power x n =
match n with
   0 -> 1
   |n when n<0 -> invalid_arg "la puissance doit etre positive"
   |n -> x * power x (n-1);;
  

let rec application p x =
match p with 
	[] -> 0
	|(e1,e2)::l -> (e1* power x e2) + application l x;;


let rec add polynome1 polynome2 =
match (polynome1),(polynome2) with
	|([],l)|(l,[]) -> l
	|((c1,d1)::l1),((c2,d2)::l2) -> 
		if d1=d2 then 
			if c1+c2=0 then 
				add l1 l2
			else 
				(c1+c2,d2)::add l1 l2
		else  
			if d1<d2 then
				(c1,d1):: add l1 polynome2
			else 
				(c2,d2):: add polynome1 l2;;

let rec soustract polynome1 polynome2 =
match (polynome1),(polynome2) with
	|([],l)|(l,[]) -> l
	|((c1,d1)::l1),((c2,d2)::l2) -> 
		if d1=d2 then 
			if c1-c2=0 then 
				soustract l1 l2
			else 
				(c1-c2,d2)::soustract l1 l2
		else  
			if d1<d2 then
				(c1,d1):: soustract l1 polynome2
			else 
				(-c2,d2):: soustract polynome1 l2;;

let rec deriv polynome =
match polynome with 
	[] -> []
	|(c,d)::polynome -> (c*d,d-1):: deriv polynome;;